package com.yawn.zdproject.dao;

import com.yawn.zdproject.entity.Project;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface ProjectDao extends JpaRepository<Project, String> {

    Project getFirstByPrefer(boolean prefer);

//    如涉及到删除和修改在需要加上@Modifying
    @Modifying
    @Query(value = "UPDATE project SET prefer=TRUE WHERE code=?1", nativeQuery = true)
    void setPreferPro(String code);

    @Modifying
    @Query(value = "UPDATE project SET prefer=FALSE WHERE prefer=TRUE", nativeQuery = true)
    void resetPreferPro();
}
